
#define GPD0CON  	(*(volatile unsigned long *)0xE02000A0)
#define GPD0DAT	        (*(volatile unsigned long *)0xE02000A4)
// PWM CLOCK
#define	TCFG0    	( *(volatile unsigned long *)0xE2500000)
#define	TCFG1    	( *(volatile unsigned long *)0xE2500004)
#define	TCON      	( *(volatile unsigned long *)0xE2500008)

#define	TCNTB0    	( *(volatile unsigned long *)0xE250000C)
#define	TCNTB1    	( *(volatile unsigned long *)0xE2500018)
#define	TCNTB2    	( *(volatile unsigned long *)0xE2500024)
#define	TCNTB3    	( *(volatile unsigned long *)0xE2500030)
#define	TCNTB4    	( *(volatile unsigned long *)0xE250003C)

#define	TCMPB0    	( *(volatile unsigned long *)0xE2500010)
#define	TCMPB1    	( *(volatile unsigned long *)0xE250001C)
#define	TCMPB2    	( *(volatile unsigned long *)0xE2500028)
#define	TCMPB3    	( *(volatile unsigned long *)0xE2500034)

#define	TCNTO0    	( *(volatile unsigned long *)0xE2500014)
#define	TCNTO1    	( *(volatile unsigned long *)0xE2500020)
#define	TCNTO2    	( *(volatile unsigned long *)0xE250002C)
#define	TCNTO3    	( *(volatile unsigned long *)0xE2500038)
#define	TCNTO4    	( *(volatile unsigned long *)0xE2500040)
#define	TINT_CSTAT 	( *(volatile unsigned long *)0xE2500044)
/*void init_clock(void)
{

    	CLK_SRC0 = 0x0;// close PLL	
    	APLL_LOCK= 0x0000FFFF; 
    	MPLL_LOCK = 0x0000FFFF;    	
    	// set PLL  	
    	APLL_CON0 =APLL_VAL;//FOUT= MDIV * FIN / (PDIV*2^(SDIV-1)) = 1000 MHz	
    	MPLL_CON = MPLL_VAL;// FOUT = MDIV*FIN/(PDIV*2^SDIV)=667 MHz		
    	CLK_SRC0= 0x10001111;// FOUT = MDIV*FIN/(PDIV*2^SDIV)=667 MHz	
}*/
void init_timer(unsigned long tcntb)
{
    	//GPD0CON = (GPD0CON & ~(0xF << 0))|0x2;
	//GPD0DAT = 0xf;
	TCON = 0;
	TCFG0= (TCFG0 & ~0x00ff00)|(0x41<<8);//设置预分频系数65
	TCFG1 =(TCFG1 & ~(0xf<<16))|(0x04<<16);// 16分频  输入时钟= PCLK /(prescaler+ 1) /divider =62500hz
	TCNTB4 = tcntb;
	TINT_CSTAT |=(0x1<<4);
	TCON |= 1<<21;// 更新TCNTB4
	TCON &= ~(1<<21);// 清手动更新位
	TCON |= (1<<20)|(1<<22);// 选择自动加载并启动timer4 
}
void irq_timer4()
{

    __asm__( 
    
    "ldr sp, = 0xD0037F80\n"
    "sub lr, lr, #4\n"  
    "stmfd sp!, {r0-r12, lr}\n"       
    : 
    : 
   );
    putc('!');
    intc_clearvectaddr();
    TINT_CSTAT |=(0x1<<9);
    __asm__(
    "ldmfd sp!, {r0-r12, pc}^ \n"       
    : 
    : 
  );
}
/*void Delay(long count)
{
    	volatile int i, j = 0;
    	volatile static int loop = 800000000/10000;
    	for(;count > 0;count--)
        	for(i=0;i < loop; i++) { j++; }
}
void main(void)
{

    GPD0CON = (GPD0CON & ~(0xF << 0))|0x2;
    GPH2CON= (GPH2CON & ~0x0000FFFF) | 0x00001111; 
    GPH2DAT|= 0x0F;
    init_clock();//初始化时钟
    init_timer(62500,10000);//初始wttimer                                   
    while(1)
    {
    }
    //TCON = 0;

}*/
